IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'FILTER')
BEGIN
    DROP TABLE [dbo].[FILTER]
END

GO

CREATE TABLE [dbo].[FILTER] ( 
	[ID]			    INT IDENTITY(1,1)   NOT FOR REPLICATION     NOT NULL,
    [NAME]   	        VARCHAR(50)         NOT NULL    UNIQUE,
    [TABLE_NAME]		VARCHAR(50),
    [TYPE]              VARCHAR(10)         NOT NULL CONSTRAINT [CK_FILTER_TYPE]
            CHECK NOT FOR REPLICATION (TYPE IN ('Personal', 'Module', 'System'))
            DEFAULT 'Personal',
    [USER_ID]    		INT

    CONSTRAINT [PK_FILTER_ID] PRIMARY KEY CLUSTERED ( 
       	[ID] 
    ) ON [PRIMARY],
    
    CONSTRAINT [FK_FILTER_USER_ID] FOREIGN KEY ( 
        [USER_ID]
    ) REFERENCES [dbo].[USER] (
        [ID]
    )
    
) ON [PRIMARY] 

CREATE INDEX [IDX_FILTER_NAME] on [dbo].[FILTER] ([NAME])

GO